package com.haiya.ocp;

/**
 * @author qiaoguoqiang
 */
public class OpenClosed2 {
    public static void main(String[] args) {
        GraphicEditor2 graphicEditor2 = new GraphicEditor2();

        graphicEditor2.drawShape(new Rectangle2());
        graphicEditor2.drawShape(new Circle2());
        graphicEditor2.drawShape(new Triangle2());

        graphicEditor2.drawShape(new Ellipse());
    }
}

/**
 * 用于绘图的类
 */
class GraphicEditor2 {
    /**
     * 接收不同的图形来画图
     * @param s
     */
    public void drawShape(Shape2 s) {
        s.draw();
    }
}

interface Shape2 {
    void draw();
}

class Rectangle2 implements Shape2 {
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}

class Circle2 implements Shape2 {
    @Override
    public void draw() {
        System.out.println("圆形");
    }
}

class Triangle2 implements Shape2 {
    @Override
    public void draw() {
        System.out.println("三角形");
    }
}

class Ellipse implements Shape2 {
    @Override
    public void draw() {
        System.out.println("椭圆");
    }
}
